/*
*  This program is free software: you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation, either version 3 of the License, or
*  (at your option) any later version.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <sourcemod>
#include <sdktools>
#include <l4d_stocks>

#include "macros.sp"
#include "helpers.sp"

public OnPluginStart()
{
	HookEvent("finale_radio_start", Event_final_radio_start, EventHookMode_Pre);
}


bool:is_in_kick_zone(client)
{
	decl Float:pos[3];
	GetClientAbsOrigin(client, pos);

	if(pos[2] < -120)
	{

		if(pos[0] > -1152) //saferoom et petite salle derriere
		{
			if(pos[1] < 2654) 
			{
				return true;
			}			
			else
			{
				return false;
			}

		}
		else if(pos[0] > -3345) //premier couloir droit
		{
			if(pos[1] < 2480) 
			{
				return true;
			}			
			else
			{
				return false;
			}

		}
		else if(pos[1] < 2675) //couloir tordu
		{
			if(pos[0] < -3326)
			{
				return true;
			}
			else
			{
				return false;
			}

		}
		else if(pos[1] < 3424)//grande salle avant de sortir
		{
			if(pos[0] < -3513)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

	}

	return false;
}

public Action:Event_final_radio_start(Handle:event, const String:name[], bool:dontBroadcast)
{
	decl String:mapname[32];
	GetCurrentMap(mapname,32);

	if(strcmp(mapname, "c2m5_concert") == 0)
	{

		decl Float:secure_pos[3] = { -512.63, 3150.83, -255.97 };

		FOR_EACH_INFECTED(client)
		{
			if(is_in_kick_zone(client))
			{
				ForcePlayerSuicide(client);
			}
		}

		FOR_EACH_SURVIVOR(client)
		{
			if(is_in_kick_zone(client))
			{
				TeleportEntity(client, secure_pos, NULL_VECTOR, NULL_VECTOR);
				ForcePlayerSuicide(client);
			}
		}

	}

	return Plugin_Continue;
}